﻿namespace Collaboris.Saf.Actions.Wss.Tests.Generated
{
    using Engine.Report;

    using Entities;

    using File;

    using Microsoft.SharePoint;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using Saf.Tests;

    using SharePoint.Wss.Files;

    /// <summary>
    /// This test was originally generated but has now been tested and verfiied by MJ
    /// </summary>
    [TestClass]
    public class WSSFilesTest
    {
        [TestMethod]
        public void AddFile_Test()
        {
            WSSTestAssistant<AddFile, AddFileInfo> addFile =
                new WSSTestAssistant<AddFile, AddFileInfo>(TestEnvironment.PublishingSite, "AddFileInfoTestWeb", "BLANKINTERNET#0");

            using (addFile)
            {
                MacroReport doReport = addFile.DoMacro();

                string newFileUrl = addFile.TestWeb.Url + "/" + addFile.FirstEntity.FileUrl;
                Assert.IsNotNull(SPFileHelper.GetFile(newFileUrl));

                MacroReport undoReport = addFile.UndoMacro();

                SPFile file = SPFileHelper.GetFile(newFileUrl);

                Assert.IsFalse(file.Exists);
            }
        }

        [TestMethod]
        public void ApproveFiles_Test()
        {
            WSSTestAssistant<ApproveFiles, ApproveFileInfo> approveFiles =
                new WSSTestAssistant<ApproveFiles, ApproveFileInfo>(TestEnvironment.PublishingSite, "ApproveFilesTestWeb", "BLANKINTERNET#1");

            using (approveFiles)
            {
                MacroReport doReport = approveFiles.DoMacro();

                SPFile file = SPFileHelper.GetFile(approveFiles.FirstEntity.FileUrls[0]);

                // TODO - work out how to get the approval status
                Assert.IsNotNull(file);
            }
        }

        [TestMethod]
        public void CheckInFiles_Test()
        {
            WSSTestAssistant<CheckInFiles, CheckInFileInfo> checkInFiles =
                new WSSTestAssistant<CheckInFiles, CheckInFileInfo>(TestEnvironment.PublishingSite, "CheckInFilesTestWeb", "BLANKINTERNET#1");

            using (checkInFiles)
            {
                MacroReport doReport = checkInFiles.DoMacro();

                SPFile file = SPFileHelper.GetFile(checkInFiles.FirstEntity.FileUrls[0]);

                // TODO - work out how to get the approval status
                Assert.IsNotNull(file);

                MacroReport undoReport = checkInFiles.UndoMacro();
            }
        }

        [TestMethod]
        public void CheckOutFiles_Test()
        {
            WSSTestAssistant<CheckOutFile, CheckOutFileInfo> checkInFiles =
                new WSSTestAssistant<CheckOutFile, CheckOutFileInfo>(TestEnvironment.PublishingSite, "CheckOutFileInfoTestWeb", "BLANKINTERNET#1");

            using (checkInFiles)
            {
                MacroReport doReport = checkInFiles.DoMacro();

                SPFile file = SPFileHelper.GetFile(checkInFiles.FirstEntity.FileUrls[0]);

                // TODO - work out how to get the approval status
                Assert.IsNotNull(file);

                MacroReport undoReport = checkInFiles.UndoMacro();
            }
        }

        [TestMethod]
        public void CopyFile_Test()
        {
            WSSTestAssistant<CopyFile, CopyFileInfo> copyFile = 
                new WSSTestAssistant<CopyFile, CopyFileInfo>(TestEnvironment.PublishingSite, "CopyFileTestWeb", "BLANKINTERNET#0");

            using (copyFile)
            {
                MacroReport doReport = copyFile.DoMacro();

                Assert.IsNotNull(SPFileHelper.GetFile(copyFile.FirstEntity.DestinationFileUrl));
            }
        }

        [TestMethod]
        public void GetFile_Test()
        {
            WSSTestAssistant<GetFiles, ListFileInfo> getfile =
                new WSSTestAssistant<GetFiles, ListFileInfo>(TestEnvironment.PublishingSite, "GetFilesTestWeb", "BLANKINTERNET#0");

            using (getfile)
            {
                MacroReport doReport = getfile.DoMacro();

                Assert.IsTrue(getfile.FirstEntity.FileNames[0] == "default.aspx");
                Assert.IsTrue(getfile.FirstEntity.FileUrls[0] == @"Pages/default.aspx");
            }
        }
    }
}